package fr.demos.cinepantin;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * Classe Facture
 * 
 */
@Entity
public class Facture implements Serializable{
	
	@Id
	private 		int 				id;
	private         int                 nofacture;
	private 		String				libFacture;
	@Temporal(TemporalType.DATE)
	private 		Date				dateFacture;
	private 		boolean				paye;
	private 		boolean				delivre; //Est-ce que la commande est livrée
    private 		ArrayList<LigneFacture> contenu = new ArrayList<LigneFacture>();
	private			double				montantTva;
	private			double				montantHt;
	private			double 				montantTtc;
	
	
	protected Facture(){
		
	}

	public Facture(int id,int nofacture, String libFacture, Date dateFacture,
			boolean paye, boolean delivre, ArrayList<LigneFacture> contenu,
			double montantTva, double montantHt, double montantTtc) {
		
		this.id = id;
		this.setNofacture(nofacture);
		this.libFacture = libFacture;
		this.dateFacture = dateFacture;
		this.paye = paye;
		this.delivre = delivre;
		this.contenu = contenu;
		this.montantTva = montantTva;
		this.montantHt = montantHt;
		this.montantTtc = montantTtc;
	}

	public int getId() {
		return id;
	}

	public void setIdFacture(int id) {
		this.id = id;
	}

	public String getLibFacture() {
		return libFacture;
	}

	public void setLibFacture(String libFacture) {
		this.libFacture = libFacture;
	}

	public Date getDateFacture() {
		return dateFacture;
	}

	public void setDateFacture(Date dateFacture) {
		this.dateFacture = dateFacture;
	}

	public boolean isPaye() {
		return paye;
	}

	public void setPaye(boolean paye) {
		this.paye = paye;
	}

	public boolean isLivre() {
		return delivre;
	}

	public void setLivre(boolean livre) {
		this.delivre = livre;
	}

	public boolean isDelivre() {
		return delivre;
	}

	public void setDelivre(boolean delivre) {
		this.delivre = delivre;
	}

	public double getMontantTva() {
		return montantTva;
	}

	public void setMontantTva(double montantTva) {
		this.montantTva = montantTva;
	}

	public double getMontantHt() {
		return montantHt;
	}

	public void setMontantHt(double montantHt) {
		this.montantHt = montantHt;
	}

	public double getMontantTtc() {
		return montantTtc;
	}

	public void setMontantTtc(double montantTtc) {
		this.montantTtc = montantTtc;
	}
	
	
	public ArrayList<LigneFacture> getContenu() {
		return contenu;
	}

	public void setContenu(ArrayList<LigneFacture> contenu) {
		this.contenu = contenu;
	}

	public int getNofacture() {
		return nofacture;
	}

	public void setNofacture(int nofacture) {
		this.nofacture = nofacture;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((contenu == null) ? 0 : contenu.hashCode());
		result = prime * result
				+ ((dateFacture == null) ? 0 : dateFacture.hashCode());
		result = prime * result + (delivre ? 1231 : 1237);
		result = prime * result + id;
		result = prime * result
				+ ((libFacture == null) ? 0 : libFacture.hashCode());
		long temp;
		temp = Double.doubleToLongBits(montantHt);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(montantTtc);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		temp = Double.doubleToLongBits(montantTva);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		result = prime * result + nofacture;
		result = prime * result + (paye ? 1231 : 1237);
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Facture other = (Facture) obj;
		if (contenu == null) {
			if (other.contenu != null)
				return false;
		} else if (!contenu.equals(other.contenu))
			return false;
		if (dateFacture == null) {
			if (other.dateFacture != null)
				return false;
		} else if (!dateFacture.equals(other.dateFacture))
			return false;
		if (delivre != other.delivre)
			return false;
		if (id != other.id)
			return false;
		if (libFacture == null) {
			if (other.libFacture != null)
				return false;
		} else if (!libFacture.equals(other.libFacture))
			return false;
		if (Double.doubleToLongBits(montantHt) != Double
				.doubleToLongBits(other.montantHt))
			return false;
		if (Double.doubleToLongBits(montantTtc) != Double
				.doubleToLongBits(other.montantTtc))
			return false;
		if (Double.doubleToLongBits(montantTva) != Double
				.doubleToLongBits(other.montantTva))
			return false;
		if (nofacture != other.nofacture)
			return false;
		if (paye != other.paye)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Facture [id=" + id + ", nofacture=" + nofacture
				+ ", libFacture=" + libFacture + ", dateFacture=" + dateFacture
				+ ", paye=" + paye + ", delivre=" + delivre + ", contenu="
				+ contenu + ", montantTva=" + montantTva + ", montantHt="
				+ montantHt + ", montantTtc=" + montantTtc + "]";
	}
	
	
	
	

	//ToDo : � modifier => affichage de la liste des elements
	
	
}
